<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>竞技之星</title>
<link href="${path }/resource/css/scale-css.css" type="text/css" rel="stylesheet" />
<!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript" src="${path }/resource/js/scale.js"></script>
</head>

<body class="body-bg">
<div class="div-container">
<div class="title-bg">
			<div class="div-title">竞技之星</div><br>
			<div class="sub-title" style="margin-top: -290px;margin-left: 260px;">跑得快</div>
		</div>
		<div class="div-bg div-line-bg5"></div>
		
		<div class="div-content" style="margin-top: -1px;">跑得快帐号 : <span id="pdkId">${gameUser.userid }</span><br></div>
		<div class="div-content" style="margin-top: -1px;">跑得快余额 : <span id="pdkBalance ">${gameUser.diamondnum }</span> 钻石<br></div>
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		
		<div class="div-content" style="margin-top: -1px;">当前转账俱乐部 : ${member.club }</div>
		
		<div class="div-content" style="margin-top: -1px;">俱乐部总积分:<span id="totalScore">${member.score + member.rewardscore }</span> 积分</div>
		
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content" style="margin-top: -1px;">操作类别 :</div>
		<div class="div-content1" style="margin-top: -30px;">
			<input type="radio" name="type" value="1" checked="checked"/> 俱乐部转入跑得快
			<br>
			<br>
		<input type="radio" name="type" value="2"/> 跑得快转入俱乐部
		</div>
		
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content" style="margin-top: -1px;">转账金额 :</div>
		<div class="div-content1" style="margin-top: -30px;">
			<input class="input-text2" type="text" id="outMoney"/>
		</div>
		
		<div class="div-bg div-line-bg120">
			<span class="div-btn div-font-size" onclick="transfer()" id="transfer">确定</span>
			<span class="div-btn div-font-size" onclick="back()" id="back">返回</span>
		</div>
	</div>
</body>
<script type="text/javascript">
	function transfer(){
		var type;
		var totalScore = parseInt($("#totalScore").text()); //俱乐部积分
		var pdkBalance = parseInt($("#pdkBalance").text()); //钻石数
		//mlg
		pdkBalance = pdkBalance/10; //钻石:积分 = 10:1
		
		var outMoney = $("#outMoney").val().trim();
		$("[name='type']").each(function(){
			if($(this).get(0).checked){
				type = $(this).val();
			}
		});
		if(outMoney==""||outMoney==null||outMoney==0){
			alert("转账数额不能为空");
			return false;
		}else if(!outMoney.match(/^\d+$/)){
			alert("转账数额只能为大于0正整数");
			return false;
		}
		if(type==1){//转入跑得快
			if(totalScore<=0||outMoney>totalScore){
				alert("当前俱乐部余额不足，赶快去充值吧！");
				return false;
			}
		}
		if(type==2){//跑得快转出
			if(pdkBalance<=0||outMoney>pdkBalance){
				alert("跑得快俱乐部余额不足，赶快去充值吧！");
				return false;
			}
		}
		if(window.confirm("您确定要转账吗？")){
		$("#transfer").attr("onclick","");
		$("#transfer").text("请稍候…");
		$("#back").attr("onclick","");
		$.ajax({
		    type: "post",
		    url: "${path}/transfer/transferApply",     
		    data: {"type":type,
		    		"outMoney":outMoney},    
		    success: function(data) {
		    	alert(data.msg);
		    	$("#transfer").text("确定");
		    	$("#back").attr("onclick","back()");
		    	if(data.code='true'){
		    		window.location.reload();//刷新当前页面.
		    	}else{
		    		$("#transfer").attr("onclick","transfer()");
		    	}
		    },
		    error: function(data) {
		    	$("#transfer").text("确定");
		    	$("#transfer").attr("onclick","transfer()");
		    	alert("网络繁忙，请稍候再试！");
		    }
		    });
		}
	}
	
	function back(){
		location.href="${path}/transfer/toTransfer";
	}
</script>
</html>